package wordroid.activitys;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.Spinner;
import android.widget.TextView;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.ArrayList;
import wordroid.business.OperationOfBooks;
import wordroid.database.DataAccess;
import wordroid.model.BookList;

public class Main extends Activity
  implements View.OnClickListener
{
  public static String BOOKNAME;
  public static final int MENU_ABOUT = 2;
  public static final int MENU_CONTACT = 3;
  public static final int MENU_MORE = 4;
  public static final int MENU_SETTING = 1;
  public static String SETTING_BOOKID = "bookID";
  private Button attentionBu;
  private TextView info;
  private Button learnBu;
  private ProgressBar learn_progress;
  private TextView learn_text;
  private Handler mHandler = new Handler();
  View myView;
  private Spinner pickBook;
  private Button reviewBu;
  private ProgressBar review_progress;
  private TextView review_text;
  private Button testBu;

  static
  {
    BOOKNAME = "BOOKNAME";
  }

  private void initSpinner()
  {
    ArrayList localArrayList = new DataAccess(this).QueryBook(null, null);
    String[] arrayOfString = new String[1 + localArrayList.size()];
    for (int i = 0; ; ++i)
    {
      if (i >= localArrayList.size())
      {
        arrayOfString[i] = "导入新词库";
        ArrayAdapter localArrayAdapter = new ArrayAdapter(this, 17367048, arrayOfString);
        localArrayAdapter.setDropDownViewResource(17367049);
        this.pickBook.setAdapter(localArrayAdapter);
       // this.pickBook.setOnItemSelectedListener(new 3(this, localArrayList));
        if (localArrayList.size() != 0)
          break;
        this.pickBook.setSelection(1);
        this.info.setText("请先从上方选择一个词库！");
        this.learnBu.setEnabled(false);
        this.reviewBu.setEnabled(false);
        this.testBu.setEnabled(false);
        this.learn_progress.setProgress(0);
        this.review_progress.setProgress(0);
        return;
      }
      arrayOfString[i] = ((BookList)localArrayList.get(i)).getName();
    }
    int j = 0;
    Log.i("BookID", DataAccess.bookID);
    while (true)
    {
      if (j < localArrayList.size());
      if (DataAccess.bookID.equals(((BookList)localArrayList.get(j)).getID()))
        this.pickBook.setSelection(j);
      ++j;
    }
  }

  private void initWidgets()
  {
	  System.out.print("");
    this.info = ((TextView)this.myView.findViewById(2131165215));
    this.learnBu = ((Button)this.myView.findViewById(2131165220));
    this.learnBu.setOnClickListener(this);
    this.pickBook = ((Spinner)this.myView.findViewById(2131165214));
    this.reviewBu = ((Button)this.myView.findViewById(2131165221));
    this.reviewBu.setOnClickListener(this);
    this.testBu = ((Button)this.myView.findViewById(2131165222));
    this.testBu.setOnClickListener(this);
    this.attentionBu = ((Button)this.myView.findViewById(2131165223));
    this.attentionBu.setOnClickListener(this);
    this.learn_progress = ((ProgressBar)this.myView.findViewById(2131165217));
    this.review_progress = ((ProgressBar)this.myView.findViewById(2131165219));
    this.review_text = ((TextView)this.myView.findViewById(2131165218));
    this.learn_text = ((TextView)this.myView.findViewById(2131165216));
    new DisplayMetrics();
    int i = -200 + getApplicationContext().getResources().getDisplayMetrics().widthPixels;
    this.learnBu.setPadding(i / 5, 0, i / 10, 0);
    this.testBu.setPadding(i / 10, 0, i / 10, 0);
    this.attentionBu.setPadding(i / 10, 0, i / 5, 0);
    initSpinner();
  }

  public void onClick(View paramView)
  {
    if (paramView == this.reviewBu)
    {
      Intent localIntent1 = new Intent();
      localIntent1.setClass(this, ReviewMain.class);
      startActivity(localIntent1);
    }
    if (paramView == this.testBu)
    {
      Intent localIntent2 = new Intent();
      localIntent2.setClass(this, TestList.class);
      startActivity(localIntent2);
    }
    if (paramView == this.attentionBu)
    {
      Intent localIntent3 = new Intent();
      localIntent3.setClass(this, Attention.class);
      startActivity(localIntent3);
    }
    if (paramView != this.learnBu)
      return;
    Intent localIntent4 = new Intent();
    localIntent4.setClass(this, study.class);
    startActivity(localIntent4);
  }

  protected void onCreate(Bundle paramBundle)
  {
    setTitle("安卓背单词--Wordroid");
    super.onCreate(paramBundle);
    setContentView(2130903051);
    this.myView = LayoutInflater.from(this).inflate(2130903052, null);
   // new 2(this).start();
    OperationOfBooks localOperationOfBooks = new OperationOfBooks();
    localOperationOfBooks.setNotify(getSharedPreferences("wordroid.model_preferences", 0).getString("time", "18:00 下午"), this);
    File localFile = new File("data/data/wordroid.model/databases");
    if (!(localFile.exists()))
      localFile.mkdir();
    if (!(new File("data/data/wordroid.model/databases/wordroid.db").exists()));
    try
    {
      FileOutputStream localFileOutputStream = new FileOutputStream("data/data/wordroid.model/databases/wordroid.db");
      byte[] arrayOfByte = new byte[8192];
      InputStream localInputStream = getResources().openRawResource(2131034112);
      int i = localInputStream.read(arrayOfByte);
      if (i <= 0)
      {
        localFileOutputStream.close();
        localInputStream.close();
        label171: DataAccess.bookID = getSharedPreferences(SETTING_BOOKID, 0).getString(BOOKNAME, "");
        localOperationOfBooks.UpdateListInfo(this);
        initWidgets();
        return;
      }
      localFileOutputStream.write(arrayOfByte, 0, i);
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
     
    }
  }

  public boolean onCreateOptionsMenu(Menu paramMenu)
  {
    paramMenu.add(0, 1, 0, "设置");
    paramMenu.add(0, 2, 1, "说明");
    paramMenu.add(0, 3, 2, "关于");
    return super.onCreateOptionsMenu(paramMenu);
  }

  protected void onDestroy()
  {
    getSharedPreferences(SETTING_BOOKID, 0).edit().putString(BOOKNAME, DataAccess.bookID).commit();
    super.onDestroy();
  }

  public boolean onOptionsItemSelected(MenuItem paramMenuItem)
  {
    switch (paramMenuItem.getItemId())
    {
    default:
    case 1:
    case 2:
    case 3:
    }
    while (true)
    {
      return super.onOptionsItemSelected(paramMenuItem);
      /*Intent localIntent3 = new Intent();
      localIntent3.setClass(this, Preference.class);
      startActivity(localIntent3);
      continue;
      Intent localIntent2 = new Intent();
      localIntent2.setClass(this, Help.class);
      startActivity(localIntent2);
      continue;
      Intent localIntent1 = new Intent();
      localIntent1.setClass(this, about.class);
      startActivity(localIntent1);*/
    }
  }

  protected void onResume()
  {
    Log.i("In Resume", DataAccess.bookID);
    initSpinner();
    super.onResume();
  }
}

/* Location:           E:\Desktop\Android\英语词汇记忆\classes_dex2jar.jar
 * Qualified Name:     wordroid.activitys.Main
 * JD-Core Version:    0.5.3
 */